public class StateMachineExample {

    public static void main(String[] args) {
        StateMachine stateMachine = new StateMachine();
        stateMachine.start();
    }
}

class StateMachine {
    private int passwordErrorCount = 0;
    private boolean isLocked = false;
    private String input = "";

    public void start() {
        System.out.println("当前处于待机状态");
        // 模拟 120s 锁定时间结束
        simulateLockTimeEnd();
    }

    private void simulateLockTimeEnd() {
        if (!isLocked) {
            // 模拟输入字符
            inputCharacter();
        } else {
            System.out.println("系统处于锁定状态，无法进行操作。");
        }
    }

    private void inputCharacter() {
        input += "a";
        if (input.length() < 4) {
            System.out.println("处于读取输入字符状态");
            // 这里可以继续输入字符或者输错密码等操作
            simulateWrongPassword();
        } else if (input.length() == 4) {
            if (isCorrectPassword()) {
                System.out.println("输入密码正确，进入系统功能选择状态");
            } else {
                passwordErrorCount++;
                if (passwordErrorCount >= 3) {
                    isLocked = true;
                    System.out.println("输错密码且错误次数>=3，进入锁定状态");
                } else {
                    System.out.println("密码错误(错误次数<3)");
                }
            }
        }
    }

    private boolean isCorrectPassword() {
        // 假设正确密码为 "abcd"
        return "abcd".equals(input);
    }

    private void simulateWrongPassword() {
        // 模拟输错密码
        if (Math.random() < 0.5) {
            inputCharacter();
        } else {
            System.out.println("输入错误密码");
            passwordErrorCount++;
            if (passwordErrorCount >= 3) {
                isLocked = true;
                System.out.println("输错密码且错误次数>=3，进入锁定状态");
            } else {
                System.out.println("密码错误(错误次数<3)");
            }
        }
    }
}